var vm_jingfeipicidanweiqueren = new Vue({
    el: "#jingfeipicidanweiqueren",
    data: {
        jingfeipiciid: $("#jingfeipiciid").val(),//经费批次id,
        deptid: $("#deptid").val(),//上级单位id,
        picijiezhishijian: $("#picijiezhishijian").val(),//批次截止时间,

        //查询字段
        deptname : '',
        shifouqueren : '',

        danweiquerenlist : [],

        //编辑用
        currentdeptid : '',
        currentpiciid : '',
        jiezhishijian : '',

        jieshouren:{
            names:'',
            ids:''
        },

        messagecontent : '',
        fuzerenshoujihaoma : '',
    },
    created : function(){
        var _this = this;

        _this.bindDanweiList();

    },
    methods: {
        bindDanweiList : function(){
            var _this = this;

            var jingfeipici_layer = layer.open({type:3});
            $.post('/system/danweiqueren/finddanweiquerenbyparentid', {
                deptid : _this.deptid,
                jingfeipiciid : _this.jingfeipiciid,
                deptname : _this.deptname,
                shifouqueren : _this.shifouqueren,
                rdm : Math.random()
            },function(ppData) {
                layer.close(jingfeipici_layer);

                if (ppData != null) {
                    if (ppData.result==1){
                        var data = ppData.resultContent;
                        _this.danweiquerenlist = data;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        getJiezhishijian:function(){
            var _this = this;

            _this.jiezhishijian=$("#jiezhishijian").val();
        },

        toShezhi:function(danweiquerenitem){

            var _this = this;

            _this.currentdeptid = danweiquerenitem.deptid;
            _this.currentpiciid = _this.jingfeipiciid;

            _this.bindShezhi();
            $("#jiezhishijianModal").modal();

        },
        bindShezhi:function(){
            var _this = this;

            var jingfeipici_layer = layer.open({type:3});
            $.post('/system/jiezhishijian/findone', {
                deptid : _this.currentdeptid,
                jingfeipiciid : _this.currentpiciid,
                rdm : Math.random()
            },function(ppData) {
                layer.close(jingfeipici_layer);

                if (ppData != null) {
                    if (ppData.result==1){

                        _this.jiezhishijian  =ppData.resultContent.jiezhishijian;
                        $("#jiezhishijian").val(_this.jiezhishijian);

                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        Shezhi:function(){
            var _this = this;

            var jingfeipici_layer = layer.open({type:3});
            $.post('/system/jiezhishijian/shezhi', {
                deptid : _this.currentdeptid,
                jingfeipiciid : _this.currentpiciid,
                jiezhishijian : _this.jiezhishijian,
                rdm : Math.random()
            },function(ppData) {
                layer.close(jingfeipici_layer);

                if (ppData != null) {
                    if (ppData.result==1){
                        layer.open({
                            time: 1000,
                            btn: [],
                            content: "设置成功!",
                        });
                        $("#jiezhishijianModal").modal('hide');
                        _this.bindDanweiList();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        bindJieshouren:function(deptid){
            var _this = this;

            $.post('/system/xiaoxi/findjieshourenbydeptid', {
                deptid : deptid,
            },function(ppData) {
                if (ppData != null) {
                    if (ppData.result==1){
                        _this.jieshouren  =ppData.resultContent;
                        $("#jieshourennames").val(_this.jieshouren.names);
                        $("#jieshourenids").val(_this.jieshouren.ids);
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        toZhanneixin:function(danweiquerenitem){
            this.bindJieshouren(danweiquerenitem.deptid)
            var str = "本批次截止时间为：" + (danweiquerenitem.jiezhishijian == null?this.picijiezhishijian : danweiquerenitem.jiezhishijian)+"，请在截止时间前确认单位变动情况"
            $("#biaoti").val("请确认单位变动情况")
            $("#neirong").val(str)
            $("#xiaoxiModalLabel").html("发送站内信")
            $("#xiaoxiModal").modal()
        },

        submitHandler:function (s) {
            var prefix = ctx + "system/xiaoxi"
            $("#form-xiaoxi-add").validate({
                focusCleanup: true
            });
            if ($.validate.form("form-xiaoxi-add")) {
                var formdata = $('#form-xiaoxi-add').serialize()
                formdata += "&zhuangtai=" + s;
                $.operate.save(prefix + "/add", formdata,(res)=>{
                    if (res.code == "0") {
                        if(s==1) {
                            layer.open({
                                time: 1000,
                                btn: [],
                                content: "发送邮件成功!",
                            });
                        }else if(s==0){
                            layer.open({
                                time: 1000,
                                btn: [],
                                content: "保存草稿成功!",
                            });
                        }
                        $.form.reset("form-xiaoxi-add");
                        $("#xiaoxiModal").modal("hide")
                    }
                });
            }
        },

        toSendMessage:function(danweiquerenitem){
            var _this = this;

            _this.fuzerenshoujihaoma = danweiquerenitem.fuzerenshoujihaoma;
            var str = "本批次截止时间为：" + (danweiquerenitem.jiezhishijian == null?this.picijiezhishijian : danweiquerenitem.jiezhishijian)+"，请在截止时间前确认单位变动情况"
            _this.messagecontent = str;
            $("#messageModalLabel").html("发送短信");
            $("#messageModal").modal()
        },

        sendmessage:function(){
            var _this = this;

            var jingfeipici_layer = layer.open({type:3});
            $.post('/system/messagecenter/send_piliang', {
                messagecontent : _this.messagecontent,
                phones : _this.fuzerenshoujihaoma,
                rdm : Math.random()
            },function(ppData) {
                layer.close(jingfeipici_layer);

                if (ppData != null) {
                    if (ppData.result==1){
                        layer.open({
                            time: 1000,
                            btn: [],
                            content: "发送成功!",
                        });
                        $("#messageModal").modal('hide');
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },
    },

})